#ifndef __BASELANG_H__
#define __BASELANG_H__

#include <string>
#include <unordered_map>
#include "../utility/options.h"
#include "../utility/log.h"
#include "../utility/os.h"

class Language
{
public:
    int extra_time = 0,extra_memory = 0;
    int lang_type = NONE_LANGUAGE;
    std::string name = "default";
    std::string compiler = "bash -c";
    // 用作编译选项
    std::string compile_option = "";
    // 用作运行选项
    std::string run_option = "";
    // 用作文件名后缀
    std::string suffix = "";
    // 禁用的系统调用
    std::vector<seccomp_ruler> disableSysCallSet = {};
    // 执行注册等行为
    Language(const std::string& name = "default");
    // 返回src文件放到dstPath下应该存储的文件或项目名
    virtual std::string detect(const std::string& src, const std::string& dstPath) const;
    // 根据源文件或项目名获得对应的可执行文件名
    // 解释性语言若不需要编译则需要重写该函数返回自身即可
    virtual std::string getBinaryFilename(std::string src) const;
    // 初始化源文件将文件拷到dst目录下，返回文件或项目所在地址
    virtual std::string prepare(const std::string& src, const std::string& dst) const;
    // 若target为空，则将在filename下直接编译，返回当前语言的编译命令
    virtual std::string compileFileStr(std::string filename, std::string target = "") const;
    // 当前语言编译出的可执行文件的执行命令
    virtual std::string runFileStr(std::string filename) const;
    virtual ~Language() = default;
};


extern std::unordered_map<std::string, const Language*> langMap;
extern std::unordered_map<std::string, std::string> suffixMap;

/*
const Language* DEFAULT_LANG = new Language{};
const Language* CPP11_LANG = new CppLanguage{" -std=c++11 "};
const Language* CPP14_LANG = new CppLanguage{" -std=c++14 "};
const Language* CPP17_LANG = new CppLanguage{" -std=c++17 "};
const Language* CPP20_LANG = new CppLanguage{" -std=c++20 "};
const Language* PYTHON3_LANG = new Py3Language{};
const Language* C99_LANG = new CLanguage{" -std=c99 "};
const Language* JAVA8_LANG = new Java8Language{};
const Language* PHP7_LANG = new Php7Language{};
const Language* MYSQL_LANG = new SqlLanguage{};
const Language* CSHARP_LANG = new CSharpLanguage{};
const Language* GO_LANG = new GoLanguage{};
const Language* LUA_LANG = new LuaLanguage{};

unordered_map<std::string, const Language*> langMap = {
    // default用来进行简单的文件拷贝
    {"default", DEFAULT_LANG},
    {"c++11", CPP11_LANG},
    {"c++14", CPP14_LANG},
    {"c++17", CPP17_LANG},
    {"c++20", CPP20_LANG},
    {"c++", CPP11_LANG},
    {"python3", PYTHON3_LANG},
    {"py", PYTHON3_LANG},
    {"cpp", CPP14_LANG},
    {"c", C99_LANG},
    {"c99", C99_LANG},
    {"java", JAVA8_LANG},
    {"java8", JAVA8_LANG},
    {"php", PHP7_LANG},
    {"php7", PHP7_LANG},
    {"sql", MYSQL_LANG},
    {"csharp", CSHARP_LANG},
    {"go", GO_LANG},
    {"lua", LUA_LANG}
};

unordered_map<std::string, std::string> suffixMap = {
    {"java", "java8"},
    {"cs", "c#"},
    {"cpp", "c++11"},
    {"c", "c99"},
    {"go", "go"},
    {"py", "python3"},
    {"php", "php3"},
    {"lua", "lua"},
    {"sql", "sql"}
};

*/

#endif /* __BASELANG_H__ */
